package com.ziyun.pop.web.modules.storeGoodsCategoryTwd.controller;

import java.util.Arrays;
import java.util.Map;

import com.ziyun.pop.modules.storeGoodsCategoryTwd.entity.StoreGoodsCategoryTwdEntity;
import com.ziyun.pop.modules.storeGoodsCategoryTwd.service.StoreGoodsCategoryTwdService;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 图文宝商品分类表
 *
 * @author xueqz
 * @email 
 * @date 2018-12-27 13:50:29
 */
@RestController
@RequestMapping("storeGoodsCategoryTwd/storegoodscategorytwd")
public class StoreGoodsCategoryTwdController {
    @Autowired
    private StoreGoodsCategoryTwdService storeGoodsCategoryTwdService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("storeGoodsCategoryTwd:storegoodscategorytwd:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = storeGoodsCategoryTwdService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{categoryId}")
    @RequiresPermissions("storeGoodsCategoryTwd:storegoodscategorytwd:info")
    public R info(@PathVariable("categoryId") Integer categoryId){
        StoreGoodsCategoryTwdEntity storeGoodsCategoryTwd = storeGoodsCategoryTwdService.getById(categoryId);

        return R.ok().put("storeGoodsCategoryTwd", storeGoodsCategoryTwd);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("storeGoodsCategoryTwd:storegoodscategorytwd:save")
    public R save(@RequestBody StoreGoodsCategoryTwdEntity storeGoodsCategoryTwd){
        storeGoodsCategoryTwdService.save(storeGoodsCategoryTwd);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("storeGoodsCategoryTwd:storegoodscategorytwd:update")
    public R update(@RequestBody StoreGoodsCategoryTwdEntity storeGoodsCategoryTwd){
        ValidatorUtils.validateEntity(storeGoodsCategoryTwd);
        storeGoodsCategoryTwdService.updateById(storeGoodsCategoryTwd);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("storeGoodsCategoryTwd:storegoodscategorytwd:delete")
    public R delete(@RequestBody Integer[] categoryIds){
        storeGoodsCategoryTwdService.removeByIds(Arrays.asList(categoryIds));

        return R.ok();
    }


}
